package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.pojo.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/admin/category")
public class CategoryController {
    @Autowired
    public CategoryService categoryService;

    @PostMapping
    public Result addType(@RequestBody CategoryDTO categoryDTO) {
        categoryService.addType(categoryDTO);
        return Result.success();
    }

    @GetMapping("/page")
    public Result findByPage(CategoryPageQueryDTO categoryPageQueryDTO) {
        PageResult byPage = categoryService.findByPage(categoryPageQueryDTO);
        return Result.success(byPage);
    }

    @DeleteMapping
    public Result deleteById(Integer id) {
        categoryService.deleteById(id);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody CategoryDTO categoryDTO){
        categoryService.update(categoryDTO);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    public Result forbidden(Integer id){
        categoryService.forbidden(id);
        return Result.success();
    }

    @GetMapping("/list")
    public Result findByType(Integer type){
        List<Category> byType = categoryService.findByType(type);
        return Result.success(byType);
    }


}
